package com.foo.designpattern.chainofresponsibility;

import junit.framework.TestCase;


/**
 * com.foo.designpattern.chainofresponsibility
 * Created with IntelliJ IDEA.
 * Created by jiang on 2016/4/21 23:32.
 *
 * @Description 测试责任链模式
 * 责任链是使多个对象都有机会处理请求，从而避免请求的发送者和接受者之间的耦合关系。
 * 将这个对象练成一条链，并沿着这条链传递该请求，知道有一个对性爱那个处理他为知。
 * 职责链可以是一条直线、一个环或者一个树形结构，最常见的职责链是直线型，即沿着一条单向的链来传递请求。
 * 公司的报销系统及常用BPM流程处理类的系统大都应该都是这种模式的。
 */
public class ChainOfResponsibilityTestCase extends TestCase {
    public void testChainOfResponsibility() {
        System.out.println("= = = = ↓↓↓责任链模式，测试开始↓↓↓ = = = =");

        // 要先组装责任链
        Handler h1 = new GeneralManager();
        Handler h2 = new DeptManager();
        Handler h3 = new ProjectManager();
        h3.setSuccerror(h2);
        h2.setSuccerror(h1);

        // 开始测试
        String test1 = h3.handleFeeRequest("张三", 300);
        System.out.println("test1 = " + test1);
        String test2 = h3.handleFeeRequest("李四", 300);
        System.out.println("test2 = " + test2);
        System.out.println("=====================");
        String test3 = h3.handleFeeRequest("张三", 600);
        System.out.println("test3 = " + test3);
        String test4 = h3.handleFeeRequest("李四", 600);
        System.out.println("test4 = " + test4);
        System.out.println("=====================");
        String test5 = h3.handleFeeRequest("张三", 1500);
        System.out.println("test5 = " + test5);
        String test6 = h3.handleFeeRequest("李四", 1500);
        System.out.println("test6 = " + test6);
        System.out.println("=====================");

        System.out.println("= = = = ↑↑↑责任链模式，测试结束↑↑↑ = = = =");
    }
}
